asm
  ld sp,$E7FF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $E000
dim seed as uinteger at $E002
dim edl as uinteger at $E004
dim ee2 as uinteger at $E006
dim ee3 as uinteger at $E008
dim expos as uinteger at $E00A
dim eypos as uinteger at $E00C
dim crid as uinteger at $E00E
dim crcl as uinteger at $E010

sub m52putsprite(tlay as uinteger, txpos as uinteger,typos as uinteger, tid as uinteger, tclut as uinteger):
  poke $C803+(tlay*4),txpos
  poke $C800+(tlay*4),typos bxor 255
  poke $C801+(tlay*4),tid
  poke $C802+(tlay*4),tclut
  end sub

sub m52putcharattr(txpos as uinteger,typos as uinteger, tid as uinteger, tclut as uinteger):
  poke $8000+txpos+(typos*32),tid
  poke $8400+txpos+(typos*32),tclut
  end sub


seed=0

for eee=$8000 to $83FF
  poke eee,1
  next

for eee=$8400 to $87FF
  poke eee,0
  next

for eee=0 to 15
  poke $8000+2+(32*30)+eee,peek(@text01+eee) '- hello world
  next

poke $8035,code("A")
poke $8435,2

for ee2=0 to 15
  for ee3=0 to 15
    poke $8000+(ee3+2)+((ee2+2)*32),(ee3)+(ee2*16)
    next:next

for ee2=0 to 7
  for ee3=0 to 15
    'poke $8000+(ee3+2)+((ee2+19)*32),4
    'poke $8400+(ee3+2)+((ee2+19)*32),(ee3)+(ee2*16)
    m52putcharattr(ee3+2,ee2+19,4,(ee3)+(ee2*16))
    next:next

expos=112
eypos=40
crid=1
crcl=1

do
  'for edl=1 to 512:next
  '- note: mpatrol on mame has no vertical joystick connectors... :S (using the second joystick for that)
  if (peek($D001)band 1=0) or (peek($D002)band 4=0) then:expos=expos+1:end if
  if (peek($D001)band 2=0) or (peek($D002)band 8=0) then:expos=expos-1:end if
  if (peek($D001)band 4=0) or (peek($D002)band 1=0) then:eypos=eypos+1:end if 
  if (peek($D001)band 8=0) or (peek($D002)band 2=0) then:eypos=eypos-1:end if
  if peek($D001)band 128=0 then:crid=crid+1:end if
  if peek($D001)band  32=0 then:crcl=crcl+1:end if

  expos=expos band 255
  eypos=eypos band 255
  crid=crid band 255
  crcl=crcl band 255

  for ee2=0 to 7
    for ee3=0 to 7
      m52putsprite((ee2*8)+ee3,expos+(ee3*16),eypos+(ee2*16),crid,crcl)
      next:next

  m52putcharattr(21,20,48+(expos mod 10),0)
  m52putcharattr(20,20,48+((int(expos/10)) mod 10),0)
  m52putcharattr(19,20,48+((int(expos/100)) mod 10),0)

  m52putcharattr(21,21,48+(eypos mod 10),0)
  m52putcharattr(20,21,48+((int(eypos/10)) mod 10),0)
  m52putcharattr(19,21,48+((int(eypos/100)) mod 10),0)

  m52putcharattr(21,22,48+(crid mod 10),0)
  m52putcharattr(20,22,48+((int(crid/10)) mod 10),0)
  m52putcharattr(19,22,48+((int(crid/100)) mod 10),0)

  m52putcharattr(21,23,48+(crcl mod 10),0)
  m52putcharattr(20,23,48+((int(crcl/10)) mod 10),0)
  m52putcharattr(19,23,48+((int(crcl/100)) mod 10),0)

  loop

'-------------------------------------------------------------------------------

text01:
asm
  defb "HELLO WORLD!!!!"
  end asm

